<template>
  <div class="email-node" :class="{ selected: selected }">
    <div class="node-header">
      <el-icon class="node-icon"><Message /></el-icon>
      <span class="node-title">{{ data.name || '邮件节点' }}</span>
    </div>
    <div class="node-content">
      <div class="email-info">
        <span class="email-subject">{{ emailSubject }}</span>
        <span class="email-recipients">{{ emailRecipients }}</span>
      </div>
    </div>
    <div class="node-handles">
      <Handle type="target" :position="Position.Top" :style="{ background: '#409eff', width: '20px', height: '20px', border: '3px solid #fff', boxShadow: '0 0 8px #409eff', zIndex: 2, cursor: 'pointer' }" />
      <Handle type="source" :position="Position.Bottom" :style="{ background: '#409eff', width: '20px', height: '20px', border: '3px solid #fff', boxShadow: '0 0 8px #409eff', zIndex: 2, cursor: 'pointer' }" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { Handle, Position } from '@vue-flow/core'
import { Message } from '@element-plus/icons-vue'

interface Props {
  id: string
  data: {
    name?: string
    emailSubject?: string
    emailRecipients?: string
  }
  selected?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  selected: false
})

const emailSubject = computed(() => {
  return props.data.emailSubject || '流程通知'
})

const emailRecipients = computed(() => {
  return props.data.emailRecipients || '未设置收件人'
})

defineOptions({
  name: 'EmailNode'
})
</script>

<style scoped>
.email-node {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  border: 2px solid #38a169;
  border-radius: 12px;
  padding: 12px;
  min-width: 120px;
  color: #2d3748;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
}

.email-node.selected {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.node-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.node-icon {
  font-size: 16px;
  color: #4a5568;
}

.node-title {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
}

.node-content {
  margin-bottom: 8px;
}

.email-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-subject {
  font-size: 10px;
  color: #4a5568;
  font-weight: 500;
}

.email-recipients {
  font-size: 10px;
  color: #718096;
}

.node-handles {
  position: relative;
}

::v-deep(.vue-flow__handle) {
  border-radius: 50% !important;
  border: 3px solid #fff !important;
  box-shadow: 0 0 8px #409eff !important;
  width: 20px !important;
  height: 20px !important;
  z-index: 2 !important;
  cursor: pointer !important;
}
</style> 